package cn.ym.ymcc.service.impl;

import cn.ym.ymcc.domain.CourseType;
import cn.ym.ymcc.domain.Teacher;
import cn.ym.ymcc.mapper.TeacherMapper;
import cn.ym.ymcc.query.TeacherQuery;
import cn.ym.ymcc.result.PageList;
import cn.ym.ymcc.service.ITeacherService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 老师表 服务实现类
 * </p>
 *
 * @author 210513347@qq.com
 * @since 2023-05-08
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public PageList<Teacher> queryPage(TeacherQuery query) {
        Wrapper<Teacher> wrapper = new EntityWrapper<>();
        if(!StringUtils.isEmpty(query.getKeyword())){
            wrapper.like("name", query.getKeyword());
        }
        Long count = Long.valueOf(teacherMapper.selectCount(wrapper));
        if(count==0){
            return new PageList<>();
        }
        List<Teacher> teachers = teacherMapper.queryData(query);
        return new PageList<>(count, teachers);
    }
}
